const AWS = require('aws-sdk');

const params = {
    HealthStatus: "ALL",
    MaxResults: 10,
    NamespaceName: "pt",
    // ServiceName: "src-pt-core-products",
};
AWS.config.update({region: 'us-east-2'});
let serviceDiscovery = {};
serviceDiscovery.refresh = serviceName => new Promise((resolve, reject) => {
    const servicediscovery = new AWS.ServiceDiscovery();
    params.ServiceName = serviceName;
    servicediscovery.discoverInstances(params, function (err, data) {
        if (err) {
            reject(err);
        } // an error occurred
        else {
            // availableServices.Content[serviceName] = data;
            console.log("refresh servicediscovery successfully [%s]...", serviceName);
            resolve(data);
        }
    });
});

module.exports = serviceDiscovery;